package cn.xscrum.vtsp.service.impl;

import java.util.List;
import cn.xscrum.common.utils.DateUtils;
import cn.xscrum.vtsp.domain.VtspActivity;
import cn.xscrum.vtsp.vo.VtspEnrollVo;
import cn.xscrum.vtsp.service.IVtspMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.xscrum.vtsp.mapper.VtspEnrollMapper;
import cn.xscrum.vtsp.domain.VtspEnroll;
import cn.xscrum.vtsp.service.IVtspEnrollService;
import cn.xscrum.common.core.text.Convert;

/**
 * 报名信息Service业务层处理
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Service
public class VtspEnrollServiceImpl implements IVtspEnrollService 
{
    @Autowired
    private VtspEnrollMapper vtspEnrollMapper;

    @Autowired
    private IVtspMessageService vtspMessageService;

    /**
	 * 查询报名信息
     * 
     * @param enrollId 报名信息ID
     * @return 报名信息
     */
    @Override
    public VtspEnroll selectVtspEnrollById(Long enrollId)
    {
        return vtspEnrollMapper.selectVtspEnrollById(enrollId);
    }

    @Override
    public Long selectPostEnrollNum(Long activityId)
    {
        return vtspEnrollMapper.selectPostEnrollNum(activityId);
    }

    @Override
    public VtspEnroll queryVtspEnrollById(Long volunteerId, Long activityId) {
        return vtspEnrollMapper.queryVtspEnrollById(volunteerId, activityId);
    }

    /**
     * 查询活动列表
     *
     * @param vtspEnroll 活动
     * @return 活动集合
     */
    @Override
    public VtspEnroll queryEnroll(VtspEnroll vtspEnroll){
        return vtspEnrollMapper.queryEnroll(vtspEnroll);
    };

    /**
	 * 查询报名信息列表
     * 
     * @param vtspEnroll 报名信息
     * @return 报名信息
     */
    @Override
    public List<VtspEnroll> selectVtspEnrollList(VtspEnroll vtspEnroll)
    {
        return vtspEnrollMapper.selectVtspEnrollList(vtspEnroll);
    }

    @Override
    public List<VtspEnrollVo> selectServiceRecord(Long volunteerId) {
        return vtspEnrollMapper.selectServiceRecord(volunteerId);
    }

    /**
	 * 新增报名信息
     * 
     * @param vtspEnroll 报名信息
     * @return 结果
     */
    @Override
    public int insertVtspEnroll(VtspEnroll vtspEnroll)
    {
        vtspEnroll.setCreateTime(DateUtils.getNowDate());
        return vtspEnrollMapper.insertVtspEnroll(vtspEnroll);
    }

    /**
	 * 修改报名信息
     * 
     * @param vtspEnroll 报名信息
     * @return 结果
     */
    @Override
    public int updateVtspEnroll(VtspEnroll vtspEnroll)
    {
        vtspEnroll.setUpdateTime(DateUtils.getNowDate());
        //对报名信息进行修改
        int row = vtspEnrollMapper.updateVtspEnroll(vtspEnroll);
        //查询完整的报名信息
        VtspEnroll enroll = vtspEnrollMapper.selectVtspEnrollById(vtspEnroll.getEnrollId());
        //5-活动报名，上下文id-报名id，消息消费者-报名活动者
        vtspMessageService.sendMessage(5,enroll.getEnrollId(),enroll.getVolunteerId());
        return row;
    }

    /**
	 * 删除报名信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteVtspEnrollByIds(String ids)
    {
        return vtspEnrollMapper.deleteVtspEnrollByIds(Convert.toStrArray(ids));
    }

    /**
	 * 删除报名信息信息
     * 
     * @param enrollId 报名信息ID
     * @return 结果
     */
    @Override
    public int deleteVtspEnrollById(Long enrollId)
    {
        return vtspEnrollMapper.deleteVtspEnrollById(enrollId);
    }

    @Override
    public VtspEnroll selectVtspEnrollByUIdAndActivityId(VtspEnroll vtspEnroll) {
        return vtspEnrollMapper.selectVtspEnrollByUIdAndActivityId(vtspEnroll);
    }

    @Override
    public VtspEnroll selectVtspEnrollByUIdAndActivityId2(Long volunteerId, Long activityId) {
        return vtspEnrollMapper.selectVtspEnrollByUIdAndActivityId2(volunteerId, activityId);
    }
}
